<template>
	<view>
		<view class="img-bg">
			<image class="img" src="./static/promote.png" mode=""></image>
		</view>
		<view class="btn-box">
			<view class="detail-wrap tp-w690">
				<view class="como" @click="handleGoCommissionList">
					<view class="txt">共获得佣金</view>
					<view class="num">￥{{balance}}</view>
				</view>
				<view class="como" @click="handleGoInvitPersonList">
					<view class="txt">邀请人数</view>
					<view class="num">{{personNum}}</view>
				</view>
			</view>

			<view class="code-wrap tp-w690">
				<view class="tit">
					<image class="img-invit" src="/pagesUser/static/code-invit.png" mode=""></image>
				</view>

				<image class="img-code" :src="codeUrl" mode=""></image>
				<view class="btn" @click="handShare">立即邀请好友</view>

				<view class="rule-wrap" @click="handleGoRuleIntroduce(10,'邀请规则')">
					<text class="icon">?</text>
					<text>规则说明</text>
				</view>
			</view>
		</view>

		<!-- <uni-popup ref="share" type="bottom" :maskClick="false">
			<view class="share-wrap">
				<view class="wechat">
					<image class="icon" src="../static/imgs/other/wechat.png" mode=""></image>
					<view>分享好友</view>
					<button class="sharebutton" type="default" open-type="share"></button>
				</view>
				<view class="btn" @click="handleClosePop">取消</view>
			</view>
		</uni-popup> -->

		<Share ref="share" :info="shareInfo" :swiperList="swiperList" shareParam="''"></Share>
	</view>
</template>

<script>
	import Share from '@/components/common/common-share.vue'
	export default {
		components: {
			Share
		},
		data() {
			return {
				codeUrl: '',
				personNum: 0,
				balance: 0,
				inviteCode: '', // 邀请码
				title: '和我一起，说走就走',

				swiperList: [], // 分享的海报背景图
				shareInfo: {}, // 分享的海报信息
			};
		},
		onLoad() {
			this.getInfo()
		},
		onShareAppMessage() {
			return {
				title: this.title,
				path: '/pages/tabbar/home?inviteCode=' + this.inviteCode,
			}
		},
		methods: {
			// 吊起分享
			handShare() {
				this.$http.get(this.$api.miniShare).then(res => {
					if (res.code === 200) {
						res.data.customer.img = this.$regeImg.test(res.data.customer.img) ? res.data.customer.img : (this.$imgUrl + res
							.data.customer.img)
						res.data.qrCode = this.$regeImg.test(res.data.qrCode) ? res.data.qrCode : (this.$imgUrl + res.data.qrCode)
						res.data.shareList.map(item => {
							item = this.$regeImg.test(item) ? item : (this.$imgUrl + item)
						})
						this.shareInfo = res.data
						this.swiperList = res.data.shareList
						// this.shareInfo.qrCode = 'https://hanglv.ysxapp.cn/profile/upload/2020/09/16/0d6bdfa12e58af420a39ee22c6b9223a.png'
						this.$refs.share.show()
					}
				})
			},
			getInfo() {
				this.$http.get(this.$api.inviteIndex).then(res => {
					if (res.code === 200) {
						this.balance = res.data.yzBalance
						this.personNum = res.data.fareNum
						this.codeUrl = res.data.url,
							this.title = res.data.inviteTitle
						this.inviteCode = res.data.inviteCode
					}
				})
			},
			handleGoCommissionList() {
				uni.navigateTo({
					url: './commissionList'
				})
			},
			handleGoInvitPersonList() {
				uni.navigateTo({
					url: './invitPersonList'
				})
			},
			//去富文本页面
			handleGoRuleIntroduce(type, name) {
				uni.navigateTo({
					url: '/pages/others/depositRule?type=' + type + '&name=' + name
				})
			},
			handleShowShare() {
				this.$refs.share.open()
			},
			handleClosePop() {
				this.$refs.share.close()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.img-bg {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.img {
			width: 100%;
		}
	}

	.detail-wrap {
		height: 208rpx;
		background: rgba(255, 255, 255, 1);
		opacity: 0.9;
		border-radius: 16rpx;
		margin-top: 500rpx;
		padding: 40rpx 80rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		font-size: 32rpx;

		.num {
			font-size: 36rpx;
			color: #00B3FF;
		}

		.como {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;
		}
	}

	.code-wrap {
		height: 790rpx;
		background: rgba(255, 255, 255, 1);
		opacity: 0.9;
		border-radius: 16rpx;
		margin-top: 30rpx;
		margin-bottom: 50rpx;
		padding: 60rpx 65rpx;
		box-sizing: border-box;

		.tit {
			text-align: center;
			font-size: 36rpx;
			color: #00B4FF;

			.img-invit {
				width: 316rpx;
				height: 34rpx;
			}
		}

		.img-code {
			display: block;
			margin: 60rpx auto;
			height: 358rpx;
			width: 358rpx;
			background-color: pink;
		}

		.btn {
			width: 560rpx;
			margin: 0 auto 40rpx;
			height: 88rpx;
			border-radius: 44rpx;
			line-height: 88rpx;
			text-align: center;
			color: #fff;
			font-size: 32rpx;
			background-color: #00B4FF;
		}

		.rule-wrap {
			color: #00B4FF;
			font-size: 28rpx;
			text-align: center;

			.icon {
				display: inline-block;
				height: 28rpx;
				width: 28rpx;
				background-color: #00B4FF;
				border-radius: 50%;
				text-align: center;
				line-height: 28rpx;
				font-size: 20rpx;
				color: #fff;
				margin-right: 10rpx;
			}
		}
	}

	.share-wrap {
		height: 298rpx;
		background-color: #fff;
		border-radius: 16rpx 16rpx 0px 0px;

		.wechat {
			height: 170rpx;
			font-size: 24rpx;
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: space-evenly;
			border-bottom: 20px solid #F5F5F5;
			position: relative;

			.icon {
				height: 64rpx;
				width: 64rpx;
				border-radius: 50%;
			}

			.sharebutton {
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				background-color: transparent;

				&::after {
					border: none;
				}
			}
		}

		.btn {
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			font-size: 32rpx;
			color: #666;
		}
	}

	.btn-box {
		position: fixed;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
	}
</style>
